﻿using Microsoft.AspNetCore.Authorization;

namespace Simple.WebApi.Controllers.System
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [Route("api/LeaveMessage/[action]")]
    [ApiController]
    [Authorize]
    public class LeaveMessageController : ControllerBase
    {
        private readonly LeaveMessageService _leaveMessageService;

        public LeaveMessageController(LeaveMessageService leaveMessageService)
        {
            _leaveMessageService = leaveMessageService;
        }

        /// <summary>
        /// 留言列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> List()
        {
            List<LeaveMessageModel> data = await _leaveMessageService.GetAsync();
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 留言查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Page([FromQuery] LeaveMessagePageInputModel model)
        {
            PageResultModel<LeaveMessageModel> data = await _leaveMessageService.GetPageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 留言增加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Add([FromBody] LeaveMessageInputModel model)
        {
            await _leaveMessageService.AddAsync(model);
            return AppResult.Status200OK("新增成功");
        }

        /// <summary>
        /// 留言删除
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Delete([FromBody] List<IdInputModel> models)
        {
            await _leaveMessageService.DeleteAsync(models.Select(m => m.Id));
            return AppResult.Status200OK("删除成功");
        }

        /// <summary>
        /// 屏蔽/恢复
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> ShiftTransfers([FromBody] IsPublishDto input)
        {
            await _leaveMessageService.IsPublish(input);
            return AppResult.Status200OK($"{(input.IsPublish ? "恢复" : "屏蔽")}成功");
        }

        /// <summary>
        /// 我的留言(移动端)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> MoveLeaveMessageGetPage([FromQuery] MoveLeaveMessagePageInputModel input)
        {
            var data = await _leaveMessageService.MoveLeaveMessageGetPageAsync(input);
            return AppResult.Status200OK(data: data);
        }

    }
}
